package com.itrip.login.controller;

import com.itrip.login.pojo.ItripUser;
import com.itrip.login.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @Author: Lenovo
 * @description: 用户Controller
 * @date: 2020/2/27 09:41
 */
@Api(description="用户登录")
@Controller
@RequestMapping("/api")
public class UserController {
    /**
     * 这是一条注释
     */
    @Resource
    private UserService userService;
    @ApiOperation(value = "用户登录")
    @GetMapping("/dologin")
    public String userLogin(@RequestParam String userCode,
                            @RequestParam String userPasswod,
                            HttpServletRequest httpServletRequest) {
        List<ItripUser> list = null;
        if (((!"".equals(userCode)) || (null != userCode)) && ((!"".equals(userPasswod)) || (null != userPasswod))) {
            list = userService.userlogin(userCode, userPasswod);
            if (!list.equals(null)) {
                for (ItripUser userlist:list) {
                    System.out.println(userlist.getUserName());
                    System.out.println(userlist.getUserPassword());
                }
                httpServletRequest.getHeader("user-agent");
                return "登录成功";
            }else {
                return "密码错误";
            }
        } else {
            return "请输入账号密码";
        }
    }
}
